#!/usr/bin/env bash
committext="提交备份"
downdir="gitbackup"
rm -f /var/local/crondata/data_backup/ruoyi*.sql
bash /var/local/backup.sh
cd /var/local
rm -rf downdir
if [ ! -d $downdir ];then
  mkdir $downdir 
  else
  echo "文件夹已经存在"
fi
cd $downdir
git init
git pull  https://gitee.com/available2099/backup.git
git remote add upstream https://gitee.com/available2099/backup.git
git fetch upstream
cp /var/local/crondata/data_backup/ruoyi*.sql ./
echo "压缩密码为lihao123压缩文件"
zip -r -P'lihao123' ruoyi.zip ./ruoyi*.sql
# 解压文件：unzip -P'lihao123' ruoyi.zip
rm -f ./ruoyi*.sql
echo "备份git数据"

rm -f gitea.zip
cd /var/local/crondata/
rm -f gitea.zip
zip -r -q -P'lihao123' gitea.zip ./gitea
cp gitea.zip  /var/local/gitbackup
cd /var/local/gitbackup
git add -A .
git commit -m  $committext
git fetch upstream
git merge --no-ff -m $committext upstream/master
git push upstream master
#  git checkout --orphan clean_log
#  git add .
#  git commit -m "备注信息"
#  git branch -D master
#  git branch -m master
#  git push -f upstream master
# 运行定时任务
# 保存用户名密码
# git config --global credential.helper store
# 0 7 * * *  bash /var/local/gitbackup.sh  /dev/null 2>&1 
